<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright 2011 KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: index.tpl 2011-03-09 01:11:30 idris $
 * @author     Idris
 */
?>
  
<?php
$this->headScript()
->appendFile( $this->baseUrl() . '/application/modules/Vote/externals/scripts/jquery-1.4.4.min.js')
->appendFile( $this->baseUrl() . '/application/modules/Vote/externals/scripts/jquery.nivo.zoom.js')
->appendScript('$kjq = $.noConflict(true);');
?>

<style type="text/css">
  /* Yeah I know little bit hacky, but I can't see other option */
  .layout_middle,
  #global_content {
    overflow: visible !important;
  }
</style>

<script type="text/javascript">
  $kjq(window).load(function(){
    $kjq('body').nivoZoom({
      speed: 500,
      zoomHoverOpacity: 0.8,
      overlay: false,
      overlayColor: '#333',
      overlayOpacity: 0.5,
      captionOpacity: 0.8
    });
  });
</script>

<div class="headline">
  <h2>
    <?php echo $this->translate('Photo Votings');?>
  </h2>
  <?php if( count($this->navigation) > 0 ): ?>
  <div class="tabs">
    <?php
        echo $this->navigation()
    ->menu()
    ->setContainer($this->navigation)
    ->render();
    ?>
  </div>
  <?php endif; ?>
</div>

<div class="layout_middle layout_vote_middle">

<div class="photo-voting-wrapper">

<?php $cnt = 0; ?>

<?php if ($this->paginator->getTotalItemCount() > 0): ?>
  
<?php foreach($this->paginator as $item): ?>

<div class="photo-voting">

  <div class="top">
    <?php $counter = 0; ?>
    <?php $challenge_id = $item->getIdentity(); ?>
    <?php foreach ($this->participants[$challenge_id] as $key => $participant): ?>
    <div class="item">
      <?php echo $this->htmlLink($participant->getPhotoUrl('thumb.profile'), $this->itemPhoto($participant, 'thumb.icon'), array('class' => 'center nivoZoom')); ?>
    </div>
    <?php $counter++; ?>
    <?php unset($this->participants[$challenge_id][$key]); ?>
    <?php if ($counter >= 5) break; ?>
    <?php endforeach; ?>
    <div class="clr"></div>
  </div>

  <div class="clr"></div>

  <div class="middle">

    <div class="left">
      <?php $counter = 0; ?>
      <?php $challenge_id = $item->getIdentity(); ?>
      <?php if (count($this->participants[$challenge_id])): ?>
      <?php foreach ($this->participants[$challenge_id] as $key => $participant): ?>
      <div class="item">
        <?php echo $this->htmlLink($participant->getPhotoUrl('thumb.profile'), $this->itemPhoto($participant, 'thumb.icon'), array('class' => 'center nivoZoom')); ?>
      </div>
      <?php $counter++; ?>
      <?php unset($this->participants[$challenge_id][$key]); ?>
      <?php if ($counter >= 3) break; ?>
      <?php endforeach; ?>
      <?php else: ?>
      &nbsp;
      <?php endif; ?>
    </div>

    <div class="center">
      <div class="item-main">
        <?php echo $this->htmlLink($item->getHref(), $this->itemPhoto($item, 'thumb.normal'), array('class' => 'block')); ?>
      </div>
    </div>

    <div class="right">
      <?php $counter = 0; ?>
      <?php $challenge_id = $item->getIdentity(); ?>
      <?php if (count($this->participants[$challenge_id])): ?>
      <?php foreach ($this->participants[$challenge_id] as $key => $participant): ?>
      <div class="item">
        <?php echo $this->htmlLink($participant->getPhotoUrl('thumb.profile'), $this->itemPhoto($participant, 'thumb.icon'), array('class' => 'center nivoZoom')); ?>
      </div>
      <?php $counter++; ?>
      <?php unset($this->participants[$challenge_id][$key]); ?>
      <?php if ($counter >= 3) break; ?>
      <?php endforeach; ?>
      <?php else: ?>
      &nbsp;
      <?php endif; ?>
    </div>

    <div class="clr"></div>

  </div>

  <div class="clr"></div>

  <div class="bottom">
    <?php $counter = 0; ?>
    <?php $challenge_id = $item->getIdentity(); ?>
    <?php foreach ($this->participants[$challenge_id] as $key => $participant): ?>
    <div class="item">
      <?php echo $this->htmlLink($participant->getPhotoUrl('thumb.profile'), $this->itemPhoto($participant, 'thumb.icon'), array('class' => 'center nivoZoom')); ?>
    </div>
    <?php $counter++; ?>
    <?php unset($this->participants[$challenge_id][$key]); ?>
    <?php if ($counter >= 3) break; ?>
    <?php endforeach; ?>
    <div class="clr"></div>
  </div>

  <div class="clr"></div>

  <div class="title">
    <?php echo $this->htmlLink($item->getHref(), $item->getTitle() . $this->htmlImage($this->baseUrl() . '/application/modules/Kowcore/externals/images/launch.gif'), array('class' => 'kow-tip-element', 'id' => 'activecontestslink-'.$item->getGuid())); ?>
  </div>

</div>

<?php $cnt++; ?>

<?php if ($cnt % 2 == 0): ?>
<div class="clr"></div>
<?php endif; ?>

<?php endforeach; ?>

<?php else: ?>

<div class="tip">
  <span>
    <?php echo $this->translate('Nobody has created a voting yet.');?>
    <?php if ($this->can_create): ?>
      <?php echo $this->translate('Be the first to %1$screate%2$s one!', '<a href="'.$this->url(array('action' => 'create', 'controller' => 'photo'), 'vote_general', true).'">', '</a>'); ?>
    <?php endif; ?>
  </span>
</div>

<?php endif; ?>

<div class="clr"></div>

</div>
  
<?php echo $this->paginationControl($this->paginator, null, null); ?>
  
</div>

<script type="text/javascript">
  var pageAction = function(page) {
    $('page').value = page;
    $('filter_form').submit();
  }

  var tagAction = function(tag) {
    $('tag').value = tag;
    $('filter_form').submit();
  }

  var searchChallenges = function() {
    if (Browser.Engine.trident) {
      document.getElementById('filter_form').submit();
    } else {
      $('filter_form').submit();
    }
  }
  
</script>

<div class="layout_right layout_vote_right">
  <?php echo $this->form->render($this); ?>

  <br />
  <?php echo $this->tagCloud($this->tags, 'tagAction'); ?>
</div>

<div class="clr"></div>